home *** CD-ROM | disk | FTP | other *** search
- /* This program
- - prints the addresses of all the PSP's currently being used in memory and
- the handles opened in each of those processes.
- Handy if you have a lot of parent and child processes loaded.
- - was compiled using Lattice 3.00h
- - ASSUMES small memory model. I was too lazy to do a segread() to get the
- ds register. Instead, I took Lattice's value in _SS since ds == ss.
- - ASSUMES your environment area does not exceed 1000 bytes. If it does you
- need to change the array, environment, and the value in movedata().
- DOS can have an environment that 32K, though most people don't make it
- that large.
-
- */
-
- struct PROG_S_PRE {
- unsigned int interrpt; /* first two bytes are the instruction int 20h */
- /* this is a carryover from CP/M when you could */
- /* jump to the first byte of your program to exit */
- unsigned int machine; /* Memory size in paragraphs (16-bytes blocks) */
- char dos1;
- char call_dis[5]; /* FAR CALL to MS-DOS function dispatcher */
- unsigned long Int22; /* previous INT 22h, terminate process address IP,CS */
- unsigned long Int23; /* previous INT 23h, CNTRL-C exit address IP,CS */
- unsigned long Int24; /* previous INT 24h, Critical Error address IP,CS */
- unsigned int pre_psp; /* previous PSP segment */
- unsigned char hndl[20]; /* file handles - FF means the handle not assigned */
- unsigned int environ; /* segment address of the environment block */
- char dos2[34];
- char dispatch[12]; /* code to call MS-DOS dispatcher INT 21 instructions */
- char fcb1[16]; /* unopened File Control Block #1 */
- char fcb2[16]; /* unopened File Control Block #2 */
- char dos3[4];
- char dta[128]; /* default Disk Transfer Area */
- } ps;
-
- extern int _psp;
- extern int _env;
- extern int _esize;
- extern int _ss;
- char environment[1000];
- char command_com[] = "COMMAND.COM";
- char *double_null();
-
- void main()
- {
-
- unsigned int psp;
- char *p;
- int first_time = 1;
-
- if( *(long *)(_env+_esize-2) != 0x00010000 )
- {
- cprintf("Your operating system does not have the name of your\n");
- cprintf("program at the end of the environment. You need DOS 3.0 or\n");
- cprintf("above. Or you are running Novell Advance Netware ver 1.02\n");
- cprintf("which clobbers the name area.\n");
- _exit(1);
- }
-
- psp = *(&_psp+1); /* get the segment word not the offset word */
- do
- {
- /* move chucks of memory into our data segment area so that we can work with it */
- movedata( psp, 0, _ss, &ps, sizeof( struct PROG_S_PRE) );
- movedata( ps.environ, 0, _ss, &environment, 1000 );
-
- /* easy way to get progname for current program */
- if( first_time )
- {
- cprintf("I'm %s with machine memory of %dK\n\n",
- ( _env + _esize +2 ), ps.machine >> 6 );
- first_time = 0;
- }
-
- if( ps.environ ) /* for COMMAND.COM */
- {
-
- /* find the name of the program following the environment space, Page 4-3 of
- MS-DOS manual, document # 8411-310-02, part # 036-014-012 */
- p = environment;
- while( *double_null( &p ));
- p += 3;
- } else {
- p = command_com;
- }
- cprintf("psp at %dK for %s", psp>>6, p );
-
- /* display which handles are active for each program */
- /* the field psp is being used as a work int - not good form but ...*/
- for( psp = 0; psp < 20; psp++)
- {
- if( ps.hndl[psp] != 0xff )
- cprintf(" %d",psp);
- }
- cprintf("\n");
- psp = ps.pre_psp;
- } while( ps.environ ); /* COMMAND.COM has nulls in this field */
- }
- char *double_null( p )
- char **p;
- {
- while( *(*p)++ );
- return( *p );
- }